package pattern.future.example1;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class FutureTask {
	public static void main(String args[]) throws InterruptedException,
			ExecutionException {
		final ExecutorService exec = Executors.newFixedThreadPool(5);
		Callable<String> call = new Callable<String>() {
			public String call() throws Exception {
				Thread.sleep(1000 * 5);
				return "Other less importance things";
			}
		};

		Future<String> task = exec.submit(call);
		Thread.sleep(1000 * 3);

		System.out.println("let's do import things");

		String obj = task.get();

		System.out.println(obj);

		exec.shutdown();
	}
}
